//
//  MTDiscoverTool.swift
//  MT
//
//  Created by ooops on 2020/5/18.
//  Copyright © 2020 张强. All rights reserved.
//

import Foundation
import RxSwift
import RxDataSources
import Moya
import Result
import MTCategory

public class MTDiscoverTool: NSObject {
    public override init() {
        super.init()
    }
}

extension MTDiscoverTool {
    
    
    /// 获取发现排行榜榜首数据
    /// - Parameters:
    ///   - provider: provider description
    ///   - complete: complete description
    ///   - failure: failure description
    class func rankingCahmpion(provider: MTProvider<MTDiscoverAPI>,
                         complete: @escaping (MTRankingModel?) -> Swift.Void,
                         failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.rankingChampion).subscribe(onNext: { (result:Result<MTRankingModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    /// 魅力排行列表
    /// - Parameters:
    ///   - provider: provider description
    ///   - complete: complete description
    ///   - failure: failure description
    class func charmList(provider: MTProvider<MTDiscoverAPI>,
                         complete: @escaping (MTRankingModel?) -> Swift.Void,
                         failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.charmRankingList).subscribe(onNext: { (result:Result<MTRankingModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
    /// 实力排行列表
    /// - Parameters:
    ///   - provider: provider description
    ///   - complete: complete description
    ///   - failure: failure description
    class func strengthList(provider: MTProvider<MTDiscoverAPI>,
                         complete: @escaping (MTRankingModel?) -> Swift.Void,
                         failure: @escaping (AnyError) -> Swift.Void) {
        
        provider.rx.requestResult(.strengthRaningList).subscribe(onNext: { (result:Result<MTRankingModel, AnyError> , isCache:Bool) in
            switch result {
            case .success(let m):
                complete(m)
            case .failure(let error):
                failure(error)
                break
            }
        }).disposed(by: globalDisposedBag)
        
    }
    
}
